<!--
 * @Author: Freude Xu
 * @Date: 2021-10-06 17:16:55
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-06 17:34:01
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>验证码</title>
</head>

<body>
    手机号码：<input type="tel"> <button>发送</button>
    <script>
        var btn = document.querySelector('button');
        var time = 29;
        btn.addEventListener('click', function() {
            this.disabled = true;
            //超时调用，一直调用
            var timer = setInterval(function() {
                //当时间为0的时候将发送按钮改回来，不禁用，并将时间设为20秒
                if (time == 0) {
                    clearInterval(timer);
                    btn.disabled = false;
                    btn.innerHTML = '发送';
                    //需要重新设定时间
                    time = 29;
                } else {
                    btn.innerHTML = '请' + time + '秒后再进行发送';
                    time--;
                }
            }, 1000);
        })
    </script>
</body>

</html>